import { createRouter ,createWebHashHistory} from "vue-router"

import Home from "./../components/Home.vue"
import Welcome from "./../components/Welcome.vue"
import Login from "./../components/Login.vue"
import index from "./../components/index.vue"
import permission from "../components/permission.vue"
import set from "./../components/set.vue"
import user from "../components/user.vue";
const routes = [
    {
        name: "welcome",
        path: "/",
        meta:{
            title: "欢迎页"
        },
        component: Welcome,
    },
    {
        name: "home",
        path: "/home",
        meta: {
            title: "首页"
        },
        component: Home,
        /* 子路由 */
        children: [{
            path: '/',
            redirect: "index"
        },{
            path: '',
            redirect: "index"
        }, {
            path: '/index',
            name: 'index',
            component: index,
            meta: {
                title: '首页',
            }
        },
            {
                path: '/permission',
                name: 'permission',
                component: permission,
                meta: {
                    title: '权限',
                    isTab: true
                }
            },
            {
                path: '/user',
                name: 'user',
                component: user,
                meta: {
                    title: '用户',
                    isTab: true
                }
            },
            
            {
                path: '/set',
                name: 'set',
                component: set,
                meta: {
                    title: '设置',
                    isTab: true
                }
            }
        ]
    },
    {
        name: "login",
        path: "/login",
        meta:{
            title: "登录"
        },
        component: Login,
    }
]

// 导航守卫
// 使用 router.beforeEach 注册一个全局前置守卫，判断用户是否登陆
/* router.beforeEach((to, from, next) => {
	if (to.path === '/login') {
		next();
	} else {
		let token = localStorage.getItem('Authorization');

		if (token === null || token === '') {
			next('/login');
		} else {
			next();
		}
	}
}); */
const router = createRouter({
    history: createWebHashHistory(),
    routes
})

export default router